package com.psmz.iwi.docanalyzer.core.document.entities;

import java.util.ArrayList;
import java.util.List;

/**
 * Grupa klasyfikowanych dokumentow.
 * 
 * @author piotrs10
 * 
 */
public class NumberOfWordsClassificationGroup {
	private NumberOfWordsGroupType groupType;
	private List<Document> documentsInGroup = new ArrayList<Document>();

	/**
	 * Konstruktor zawierajacy obowiazkowe parametry.
	 * 
	 * @param groupType
	 */
	public NumberOfWordsClassificationGroup(NumberOfWordsGroupType groupType) {
		this.groupType = groupType;
	}

	/**
	 * Konstruktor zawierajacy wszystkie parametry.
	 * 
	 * @param groupType
	 * @param documentsInGroup
	 */
	public NumberOfWordsClassificationGroup(NumberOfWordsGroupType groupType,
			List<Document> documentsInGroup) {
		this.groupType = groupType;
		this.documentsInGroup = documentsInGroup;
	}

	public NumberOfWordsGroupType getGroupType() {
		return groupType;
	}

	public void setGroupType(NumberOfWordsGroupType groupType) {
		this.groupType = groupType;
	}

	public List<Document> getDocumentsInGroup() {
		return documentsInGroup;
	}

	public void setDocumentsInGroup(List<Document> documentsInGroup) {
		this.documentsInGroup = documentsInGroup;
	}

	public boolean addDocument(Document d) {
		return documentsInGroup.add(d);
	}

	public boolean removeDocument(Document d) {
		return documentsInGroup.remove(d);
	}

	public boolean addAllDocuments(List<? extends Document> c) {
		return documentsInGroup.addAll(c);
	}

	public boolean removeAllDocuments(List<?> c) {
		return documentsInGroup.removeAll(c);
	}

	public int getNumberOfDocuments() {
		return documentsInGroup.size();
	}

	public Integer getDocumentIndex(Document document) {
		return documentsInGroup.indexOf(document);
	}

	public Document getDocumentOnPosition(int position) {
		if (position >= documentsInGroup.size() || position < 0) {
			return null;
		}

		return documentsInGroup.get(position);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((groupType == null) ? 0 : groupType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NumberOfWordsClassificationGroup other = (NumberOfWordsClassificationGroup) obj;
		if (groupType != other.groupType)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return groupType.getDescription();
	}

}
